package LeetCode.leetcode;

/**
 * @author leiwenkang
 * @date 2020/6/17
 */
public class Test746使用最小花费爬楼梯 {
    public static void main(String[] args) {
//        int[] cost = {1, 100, 1, 1, 1, 100, 1, 1, 100, 1};
        int[] cost = {0 , 0 , 1, 1};
        System.out.println(minCostClimbingStairs(cost));
    }
    public static int minCostClimbingStairs(int[] cost) {
        if (cost == null || cost.length == 0) {
            return 0;
        }

        int[] dp = new int[cost.length];
        dp[0] = cost[0];
        dp[1] = Math.min(cost[0], cost[1]);
        for (int i = 2; i < cost.length; i++) {
            dp[i] = Math.min(dp[i - 1], dp[i - 2] + cost[i]);
        }

        return dp[cost.length - 1];
    }
}
